﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using System.Windows;
using System.Diagnostics;
using System.IO;
using System.Xml;


using System.Xml.Serialization;

namespace AI
{

    public class MyCar
    {



        public void MoveCar(AIOperations mainPort,double left, double right)
        {

            Vector vel = new Vector(left, right);

            if (_Velocity == 0 && vel.Length == 0)
                return;

            _Velocity = 0.00004 * vel.Length;

            DriveInfo body = new DriveInfo();

            // 현재 시스템은 바로전 움직인 정보가 반영이 안되여있다. 이것을 임시로 이렇게 표현함
            body.left = left;
            body.right = right;

            mainPort.Post(new NotifyDrive(body));

            //_BeforLeft = left;
            //_BeforRight = right;


        }


        public void UpdateDiffInfo(double elapsedTime)
        {
            _Pos += Dir * Velocity * elapsedTime;
        }


        public Vector Pos { get { return _Pos; } set { _Pos = value; } }
        public Vector _Pos = new Vector();

        public Vector Dir { get { return _Dir; } set { _Dir = value; } }
        public Vector _Dir = new Vector();

        public Vector TargetDir { get { return _TargetDir; } set { _TargetDir = value; } }
        public Vector _TargetDir = new Vector();

        /// <summary>
        /// 예상 속도
        /// </summary>
        public double Velocity { get { return _Velocity; } set { _Velocity = value; } }
        double _Velocity = -1d;


        public double VelAddCount { get { return _VelAddCount; } set { _VelAddCount = value; } }
        double _VelAddCount = 1;

        /// <summary>
        /// 
        /// </summary>
        public double Movement { get { return _Movement; } set { _Movement = value; } }
        double _Movement = 1; //

        public void UpdateDiffInfo(double diffX, double diffY)
        {
            Vector diff = new Vector(diffX, diffY) * 1.0 / Movement;
            _Velocity += (diff.Length - _Velocity) / _VelAddCount;
            _VelAddCount++;
        }

        // 0.1초로 예상하고
        public void UpdateMove()
        {
            _Pos.X += Dir.X * (Velocity / 0.1);
            _Pos.Y += Dir.Y * (Velocity / 0.1);
        }

    }
}
